#include <Arduino.h>

// put function declarations here:
int seg_a = 3;
int seg_b = 4;
int seg_c = 6;
int seg_d = 9;
int seg_e = 10;
int seg_f = 12;
int seg_g = 11;
int seg_dp = 5;
int digit_pin = 2;

void show_num(int num)
{
  if (num < 0 || num > 9)
    return;

  switch (num)
  {
  case 0:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, LOW);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, HIGH);
    digitalWrite(seg_dp, HIGH);
    break;
  case 1:
    digitalWrite(seg_a, HIGH);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, HIGH);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, HIGH);
    digitalWrite(seg_g, HIGH);
    digitalWrite(seg_dp, HIGH);
    break;
  case 2:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, HIGH);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, LOW);
    digitalWrite(seg_f, HIGH);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 3:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, HIGH);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 4:
    digitalWrite(seg_a, HIGH);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, HIGH);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 5:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, HIGH);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 6:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, HIGH);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, LOW);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 7:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, HIGH);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, HIGH);
    digitalWrite(seg_g, HIGH);
    digitalWrite(seg_dp, HIGH);
    break;
  case 8:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, LOW);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  case 9:
    digitalWrite(seg_a, LOW);
    digitalWrite(seg_b, LOW);
    digitalWrite(seg_c, LOW);
    digitalWrite(seg_d, LOW);
    digitalWrite(seg_e, HIGH);
    digitalWrite(seg_f, LOW);
    digitalWrite(seg_g, LOW);
    digitalWrite(seg_dp, HIGH);
    break;
  }
}

void setup()
{
  // put your setup code here, to run once:
  pinMode(digit_pin, LOW);
  pinMode(seg_a, OUTPUT);
  pinMode(seg_b, OUTPUT);
  pinMode(seg_c, OUTPUT);
  pinMode(seg_d, OUTPUT);
  pinMode(seg_e, OUTPUT);
  pinMode(seg_f, OUTPUT);
  pinMode(seg_g, OUTPUT);
  pinMode(seg_dp, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  for (int i = 0; i < 10; i++)
  {
    show_num(i);
    digitalWrite(digit_pin,HIGH);
    delay(1000);
    digitalWrite(digit_pin,LOW);
  }
  
}

// put function definitions here: